﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;

namespace TotalNews.Models
{
    public class tbl_Theme
    {

        public int ID
        {
            get;
            set;
        }
        public string Name
        {
            get;
            set;
        }
        public int CateID
        {
            get;
            set;
        }
        
    }
    
    public class Themes
    {
        XElement xmlTheme = XElement.Load(HttpContext.Current.Server.MapPath("~/Models/Themes.xml"));
        private List<tbl_Theme> m_themes = new List<tbl_Theme>();
        public static object m_locker = new object();
        public static Themes m_instace;

        public static Themes Instace
        {
            get
            {

                if (m_instace == null)
                {
                    lock (m_locker)
                    {
                        if (m_instace == null)
                        {
                            m_instace = new Themes();
                        }
                    }
                }
                return m_instace;
            }
        }
        public tbl_Theme GetTheme(int catID)
        {
            tbl_Theme rs = m_themes.Where(p => p.CateID == catID).FirstOrDefault();
            return rs;
        }

        public Themes()
        {
            m_themes = (from q in xmlTheme.Elements("theme")
                        select new tbl_Theme
                        {
                            CateID = int.Parse(q.Element("CateID").Value),
                            Name = q.Element("Name").Value
                        }
                                       ).ToList();
        }
    }
}